#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/7/3 16:45
# @Author  : Chenmm
# @File    : redis.py
# @Software: PyCharm


import os
from aioredis import Redis, create_redis_pool


async def sys_cache() -> Redis:
    """
    系统缓存
    :return: cache 连接池
    """
    # 从URL方式创建redis连接池
    redis = await create_redis_pool(
        f"redis://{os.getenv('CACHE_HOST', '127.0.0.1')}:{os.getenv('CACHE_PORT', 6379)}",
        db=int(os.getenv('CACHE_DB', 0)),
        password=None,
        encoding='utf-8'
    )
    return redis


async def code_cache() -> Redis:
    """
    系统缓存
    :return: cache 连接池
    """
    # 从URL方式创建redis连接池
    redis = await create_redis_pool(
        f"redis://{os.getenv('CACHE_HOST', '127.0.0.1')}:{os.getenv('CACHE_PORT', 6379)}",
        db=int(os.getenv('CACHE_DB', 1)),
        password=None,
        encoding='utf-8'
    )
    return redis

